//
//  ViewController.m
//  UI07_相册滚动
//
//  Created by dllo on 16/6/14.
//  Copyright © 2016年 dllo. All rights reserved.
//
#define ScreenWidth [UIScreen mainScreen].bounds.size.width
#define ScreenHeight [UIScreen mainScreen].bounds.size.height

#import "ViewController.h"
#import "SecondViewController.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"相册";
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.95 green:0.92 blue:0.88 alpha:1.00];
    [self requestData];
    [self createSubView];
}
- (void)requestData{
    self.photoArray = [NSMutableArray array];
    for (NSInteger i = 1; i <= 6; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld.JPG", i]];
        [self.photoArray addObject:image];
    }
    
}
- (void)createSubView{
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - 64)];
    //图片容量
    scrollView.contentSize = CGSizeMake(ScreenWidth, (self.photoArray.count / 2 + self.photoArray.count % 2) * ScreenHeight / 2);
    scrollView.contentOffset = CGPointMake(0, 0);
    [self.view addSubview:scrollView];
    for (NSInteger i = 1; i <= self.photoArray.count; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((i - 1 ) % 2 * ScreenWidth / 2, (i - 1) / 2 * ScreenHeight / 2, ScreenWidth / 2, ScreenHeight / 2)];
        imageView.image =  [self.photoArray objectAtIndex:i - 1];
        imageView.userInteractionEnabled = YES;
        imageView.tag  = 1000 + i;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapImageView:)];
        [imageView addGestureRecognizer:tap];
        [scrollView addSubview:imageView];
        [imageView release];
        
        
    }
    
}
- (void)didTapImageView:(UITapGestureRecognizer *)tap{
    SecondViewController *svc = [[SecondViewController alloc] init];
    svc.imageArray1 = self.photoArray;
    svc.numPhotos = tap.view.tag - 1000;
    [self.navigationController pushViewController:svc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
